#include "Common.h"
#include "qglobal.h"

namespace Jonathan
{
   const QString Common::BOOK ("Book");
   const QString Common::CHAPTER ("Chapter");
   const QString Common::VERSE ("Verse");
   const QString Common::TEXT ("Text");
   const QString Common::HEADER ("Header");
   const QString Common::FOOTER ("Footer");
   const QString Common::NOTES ("Notes");
   const QString Common::PREFACE ("Preface");

   const QString Common::ALIGN_CENTER ("center");
   const QString Common::ALIGN_LEFT ("left");
   const QString Common::ALIGN_RIGHT ("right");

   /**
    * @brief Gets and Icon from the given type.
    *
    * @param iconId Type of icon to get.
    * @return QIcon Requested icon.
    */
   QIcon Common::GetIcon (IconType iconId)
   {
      switch (iconId)
      {
      case ICON_Book:
         return QIcon(":/Images/Images/Book.png");
      case ICON_SubBook:
         return QIcon(":/Images/Images/SubBook.png");
      case ICON_Chapter:
         return QIcon(":/Images/Images/Chapter.png");
      case ICON_Next_Chapter:
         return QIcon(":/Images/Images/Next_Chapter.png");
      case ICON_Previous_Chapter:
         return QIcon(":/Images/Images/Previous_Chapter.png");
      case ICON_Exit:
         return QIcon(":/Images/Images/Exit.png");
      case ICON_Options:
         return QIcon(":/Images/Images/Options.gif");
      case ICON_Start:
         return QIcon(":/Images/Images/Start.png");
      case ICON_Jonathan:
      default:
         return QIcon(":/Images/Images/Jonathan.ico");
      }
   }

   /**
    * @brief Generates a random number.
    *
    * @param low Low end of range to generate.
    * @param high High end of range to generate.
    * @return int Random number in between range.
    */
   int Common::RandomInt (int low, int high)
   {
      return qrand() % ((high + 1) - low) + low;
   }

   /**
    * @brief Gets the style for labels.
    *
    * @return QString Style for labels.
    */
   QString Common::GetLabelStyle ()
   {
      QString style = "color: rgb(255, 255, 255); font: 75 10pt \"Tahoma\";";
      //style.append ("background-color: qlineargradient(spread:pad, x1:1, y1:1, ");
      //style.append ("x2:1, y2:0, stop:0 rgba(45, 77, 167, 255), stop:0.400545 ");
      //style.append ("rgba(53, 92, 200, 255), stop:0.487738 rgba(70, 105, 200, 255), ");
      //style.append ("stop:1 rgba(108, 133, 200, 255));");
      style.append ("background-color: qlineargradient(spread:pad, x1:1, y1:1, x2:1, y2:0,");
      style.append ("stop:0 rgba(29, 29, 29, 255), stop:0.472637 rgba(29, 29, 29, 255), ");
      style.append ("stop:0.562189 rgba(40, 40, 40, 255), stop:1 rgba(95, 95, 95, 255));");

      return style;
   }

   /**
    * @brief Gets the HTML to start a html document.
    *
    * @return QString HTML for a html document start.
    */
   QString Common::HtmlStart ()
   {
      return "<html><heading><title>Jonathan Reader</title></heading><body>";
   }

   /**
    * @brief Gets the HTML to end a html document.
    *
    * @return QString HTML for a html document end.
    */
   QString Common::HtmlEnd ()
   {
      return "</body></html>";
   }

   /**
    * @brief Gets the HTML to start a table.
    *
    * @return QString HTML for a table start.
    */
   QString Common::TableStart ()
   {
      QString tableText = Common::HtmlStart ();
      tableText.append ("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" style=\"border:0px;\">");
      return tableText;
   }

   /**
    * @brief Gets the HTML to end a table.
    *
    * @return QString HTML for a table end.
    */
   QString Common::TableEnd ()
   {
      QString tableText = "</table>";
      tableText.append (Common::HtmlEnd ());
      return tableText;
   }

   /**
    * @brief Gets the HTML for a column displaying a chapter/verse label.
    *
    * @param hAlign Alignment of cell.
    * @return QString HTML for a column displaying a chapter/verse label.
    */
   QString Common::VerseCell (QString hAlign)
   {
      return "<td valign=\"top\" style=\"color:DarkRed; font-weight:bold;\" align=\"" + hAlign + "\">";
   }

   /**
    * @brief Gets the HTML for a column displaying a bold label.
    *
    * @param hAlign Alignment of cell.
    * @param colSpan Column span for cell
    * @return QString HTML for a column displaying a bold label.
    */
   QString Common::BoldCell (QString hAlign, int colSpan)
   {
      QString cell = "<td";
      cell.append (" valign=\"top\"");
      cell.append (" style=\"font-weight:bold;\"");
      cell.append (" align=\"");
      cell.append (hAlign);
      cell.append ("\"");
      cell.append (" colspan=\"");
      cell.append (QString::number (colSpan));
      cell.append ("\"");
      cell.append (">");
      return cell;
   }
}
